package com.dianda.controller;

import com.dianda.pojo.Classmate;
import com.dianda.pojo.Messages;
import com.dianda.pojo.MessagesResult;
import com.dianda.pojo.Result;
import com.dianda.service.ClassmateService;
import com.dianda.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class MessagesController {

    @Autowired
    MessagesService service;

    @PostMapping("/app7/messages/list")
    public MessagesResult getMessagesList() {
        List<Messages> list = service.getMessagesList();
        MessagesResult r = new MessagesResult();
        if (list != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setList(list);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }

    @PostMapping("/app9/messages/findone")
    public MessagesResult getMessagesById(@RequestBody Messages messages){
        Integer id =messages.getId();
        Messages messages1=service.findById(id);
        MessagesResult r=new MessagesResult();
        if (messages1 != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setMessages(messages1);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
    @PostMapping("/app8/messages/add")
    public MessagesResult addMessages(@RequestBody Messages messages){
        Date date = new Date();
        messages.setDate(new java.sql.Date(date.getTime()));//获取当前时间
        Messages messages1=service.add(messages);
        MessagesResult r=new MessagesResult();
        if (messages1 != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setMessages(messages1);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
}
